---冲锋组件
---@class Battle.SkillChargeComponent:Battle.SkillComponent
local SkillChargeComponent = Battle.CreateClass("SkillChargeComponent",Battle.SkillComponent)
Battle.SkillChargeComponent = SkillChargeComponent

function SkillChargeComponent:OnExecute()
    self.actor = self.skill.actor
    local target = self.skill.emitter:CalcReleaseTarget()
    if target == nil then
        logError(self.actor.id.." 找不到目标，无法向目标移动")
        return
    end
    self:RegUpdate(true)
    self.targetPos = Vector3.New()
    self.targetPos:SetV(target:GetPos())
    self.moveDir = (self.targetPos - self.actor.pos):SetNormalize()
    self.isArrive = false
    self.actor:RotateTowards(self.targetPos.x-self.actor.pos.x,0,self.targetPos.z-self.actor.pos.z)
end
function SkillChargeComponent:Update(dt)
    if not self.isExecute then return end
    if self.targetPos == nil then return end
    if self.isArrive then return end
    local chargeType = self.skill.skillData.f_Charge.type

    local speed = self.actor.attrSystem:GetSpeed()
    local x = self.actor.pos.x + self.moveDir.x * speed * dt
    local z = self.actor.pos.z + self.moveDir.z*speed* dt
    self.actor:SetPos(x,0,z)

    if chargeType == 1 then--撞到指定目标停止
        if Vector3.DistanceSqr(self.actor.pos,self.targetPos) <= (self.actor.radius*2+0.01)^2 then
            self.skill:Hit()
            self.skill:End()
            self.isArrive = true
        end
    elseif chargeType == 2 then--撞到首个目标停止
        logError("功能未实现")
    elseif chargeType == 3 then--技能时机结束
        logError("功能未实现")
    elseif chargeType == 4 then--冲锋固定距离 （如果是4，后面填写距离参数）
        logError("功能未实现")
    else
        logError("功能未实现")
    end

end
